<template>
  <div class="salelist">
    <van-nav-bar fixed left-text="返回" left-arrow :title="!isWeixin() ? '销售记录' : ''" @click-left="handleBack" />
    <div class="inner">
      <div class="pageLoading" v-if="pageLoading">
        <van-loading type="spinner" vertical>加载中...</van-loading>
      </div>
      <div class="have" v-if="!pageLoading && list.length">
        <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
          <div class="have-item" v-for="(item, index) in list" :key="index">
            <div class="item-top">
              <div class="clumns between">
                <div class="text">购买会员：{{ maskPhoneNumber(item.phone) }}</div>
                <div class="text">
                  成交金额：<span class="bluecolor">{{ item.price }}元</span>
                </div>
              </div>
              <div class="clumns">
                <div class="text">购买时间：{{ item.addtime ? dayjs.unix(item.addtime).format('YYYY-MM-DD HH:mm:ss') : '-' }}
                </div>
              </div>
              <div class="clumns">
                <div class="text bluecolor">
                  转单信息：{{ item.title }}
                </div>
              </div>
            </div>
          </div>
        </van-list>
      </div>
      <div class="none" v-if="!pageLoading && !list.length">
        <van-empty description="暂无记录" />
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { getCookie, encryptPhoneNumber } from "@/utils/index";
import { ref, reactive } from "vue";
import { useRouter } from "vue-router";
import { isWeixin } from "@/utils/index";
import { procureordersApi } from "@/api/user";
import dayjs from "dayjs";
const router = useRouter();
const list = ref();
const pageLoading = ref(false);
const finished = ref(false);
const loading = ref(false);
const pagination = reactive({
  pageNo: 1,
  pageSize: 10,
})
const handleBack = () => {
  if (history.state?.back) {
    router.back()
  } else {
    router.push('/user')
  }
};
const getList = async () => {
  pageLoading.value = true
  let { data } = await procureordersApi({
    uid: getCookie('token') ? Number(getCookie('token')) : '',
    pageNo: pagination.pageNo,
    pageSize: pagination.pageSize
  })
  list.value = data.data || []
  if (data.totalPage === 1) {
    finished.value = true
  }
  pageLoading.value = false
}
getList()
const onLoad = async () => {

  pagination.pageNo++
  let { data } = await procureordersApi({
    uid: getCookie('token') ? Number(getCookie('token')) : '',
    pageNo: pagination.pageNo,
    pageSize: pagination.pageSize
  })
  loading.value = false
  list.value = [...list.value, ...data.data]
  if (pagination.pageNo >= data.totalPage) {
    finished.value = true
  }
};
const maskPhoneNumber = (phoneNumber:any)=> {
  return phoneNumber.substring(0, 3) + '********';
}




</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>
